#include "inet_address.h"

using namespace uvpp;

InetAddress::InetAddress(const std::string&& ip, unsigned short port, IPFamily ipv /* = IPFamily::IPv4 */)
	:_ip(ip),
	_port(port),
	_ipv(ipv)
{
	if (ipv == IPFamily::IPv4)
	{
		::uv_ip4_addr(ip.c_str(), port, &_ip4);
	}
	else {
		::uv_ip6_addr(ip.c_str(), port, &_ip6);
	}
}

InetAddress::InetAddress(const std::string& ip, unsigned short port, IPFamily ipv /* = IPFamily::IPv4 */)
	:InetAddress(std::move(ip), port, ipv)
{

}

InetAddress::InetAddress(const sockaddr* addr, IPFamily ipv /* = IPFamily::IPv4 */)
{

}

const sockaddr* InetAddress::addr()
{
	return (_ipv == IPFamily::IPv4) ? reinterpret_cast<const sockaddr*>(&_ip4) : reinterpret_cast<const sockaddr*>(&_ip6);
}
